---
title: Dynamic Configuration
---

import { Tabs, TabItem } from '@astrojs/starlight/components';

## TypeScript

Instead of `knip.json`, you can use a JavaScript or TypeScript file for a
dynamic configuration and type annotations:

<Tabs>
  <TabItem label="TypeScript">

    ```ts title="knip.ts"
    import type { KnipConfig } from 'knip';

    const config: KnipConfig = {
      entry: ['src/index.ts'],
      project: ['src/**/*.ts'],
    };

    export default config;
    ```

  </TabItem>

  <TabItem label="JavaScript">

    ```js title="knip.js"
    const config = {
      entry: ['src/index.ts'],
      project: ['src/**/*.ts'],
    };

    export default config;
    ```

  </TabItem>
</Tabs>

## Function

You can export a regular or async function that returns the configuration object
as well:

<Tabs>
  <TabItem label="TypeScript">

    ```ts title="knip.ts"
    import type { KnipConfig } from 'knip';

    const config = async (): Promise<KnipConfig> => {
      const items = await fetchRepoInfo();

      return {
        entry: ['src/index.ts', ...items],
        project: ['src/**/*.ts'],
      };
    };

    export default config;
    ```

  </TabItem>

  <TabItem label="JavaScript">

    ```ts title="knip.js"
    const config = async () => ({
      entry: ['src/index.ts'],
      project: ['src/**/*.ts'],
    });

    export default config;
    ```

  </TabItem>
</Tabs>
